package servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.DBHelper;

/**
 * Servlet implementation class Hire
 */
@WebServlet("/Hire")
public class Hire extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Hire() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    protected void handHire(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException{
    	
    	String employeeUsername = request.getParameter("employeeUsername");
    	
    	Connection con = DBHelper.getConnection();
		PreparedStatement sql = con.prepareStatement("update applyjob set state = 'true' where EMPLOYEEUSERNAME = ?");
		sql.setString(1, employeeUsername);
    	
		sql.executeUpdate();
		
		sql.close();
		con.close();
    	
    	request.getRequestDispatcher("EmployerMessage").forward(request, response);
    	
    }
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {
			handHire(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {
			handHire(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
